<?php
class shopListallControl extends skymvc{
	
	public function __construct(){
		parent::__construct();
		
	}
	
	public function onInit(){
	 
	}
	public function onDefault(){
		 
		$limit=24;
		$start=get('per_page','i');
		$where=" status=2 AND sendall=1";
		$url="/index.php?m=shoplist";
		$catid=get('catid','i');
		if($catid){
			$cat=M("category")->selectRow("catid=".$catid);
			$catids=M("category")->id_family($catid);
			$where.=" AND catid in("._implode($catids).")";
			$url.="&catid=".$catid;
		}
		$keyword=get_post('keyword','h');
		if($keyword){
			$where.=" AND shopname like '%".$keyword."%'";
			$url.="&keyword=".urlencode($keyword);
		}
	 
		
		switch(get('filter')){
			case 'cspf':
					$where.=" AND cspf=1 ";
				break;
	
				break;
			case 'isnew':
					$where.=" AND isnew=1";
				break;
		}
		$url.="&filter=".get('filter','h');
		$ob=get('orderby','h');
		switch($ob){
			case 'distance':
					$orderby='grade DESC';
				break;
			case 'sold_num':
					$orderby='sold_num DESC';
				break;
			case 'raty_grade':
					$orderby='raty_grade DESC';
				break;
			default:
				$orderby='grade DESC';
			 	break;
		}
		$option=array(
			"where"=>$where,
			"start"=>$start,
			"limit"=>$limit,
			"order"=>$orderby
		);
		$rscount=true;
		$data=M("shop")->select($option,$rscount);
		$pagelist=$this->pagelist($rscount,$limit,$url);

	
		$per_page=$start+$limit;
		$per_page=$per_page>=$rscount?0:$per_page;
		$sclist=M("site_city")->children(0);
		$sdata=array(
			"list"=>$data,
			"rscount"=>$rscount,
			"pagelist"=>$pagelist,
			"per_page"=>$per_page,
			"scarea"=>$scarea,
			"sclist"=>$sclist,
			"cat"=>$cat,
			"catlist"=>M("category")->children(0,MODEL_SHOP_ID)
		); 
		 
		$this->smarty->goassign($sdata);	
		$this->smarty->display("shoplist/all.html");
	}
	/**
	*全文索引版
	*/
	public function onSphinx(){
		
	}
	
	 
	
}

?>